Creating a Complex Polygon

This example demonstrates how to create a polygon based on a multipolygon geometry and set its properties. This example uses the IGeometryCreator (CreateGeometryFromWKT, CreateLinearRingGeometry, CreatePolygonGeometry) and ICreator80 (CreatePolygon, CreateColor, GeometryCreator), IPosition80 (Distance, Pitch) and INavigate80 (FlyTo) properties and methods.

 

private void btnComplex3DPolygon(object sender, EventArgs e)

        {

            try

            {

                // create TE API object

                var SGWorld = new SGWorld80();

 

                // Create polygon with hole geometry from well-known-text

                var complexGeometry1 = SGWorld.Creator.GeometryCreator.CreateGeometryFromWKT(@"POLYGON(

                                (-80.900091 26.739261,-80.906338 26.840896,-80.591731 26.951601,-80.809248 26.717179,-80.900091 26.739261),

                                (-80.873569 26.819371,-80.81616 26.772908,-80.811242 26.846308,-80.873569 26.819371)

                                )");

 

                // Create polygon

                // Create line color using creator by specifying red,green,blue,alpha values

                var lineColor1 = SGWorld.Creator.CreateColor(255, 0, 0, 0);

                var fillColor1 = "#00ff00"; // we can also specify color using HTML notation

                var polygon1 = SGWorld.Creator.CreatePolygon(complexGeometry1, lineColor1, fillColor1, AltitudeTypeCode.ATC_ON_TERRAIN, string.Empty, "Polygon with hole");

 

                // create multipolygon from array of x,z,y points

 

                // Polygon geometry consists of LinearRing that specifies exterior ring and array of LinearRing geometries that specify interior rings

                // create exterior ring using array of coordinates

                var exteriorRing = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry(new double[] { -80.593456, 26.692189, 1000, -80.569379, 26.654723, 2000, -80.482195, 26.724591, 1000, -80.55208, 26.771137, 1000 });

                var interiorRing1 = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry(new double[] { -80.577327, 26.713192, 1000, -80.568001, 26.726351, 1000, -80.569138, 26.715869, 1000 });

                var interiorRing2 = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry(new double[] { -80.55315, 26.691784, 2000, -80.555867, 26.673088, 2000, -80.5252610, 26.688447, 2000 });

 

                var complexGeometry2 = SGWorld.Creator.GeometryCreator.CreatePolygonGeometry(exteriorRing, new ILinearRing[] { interiorRing1, interiorRing2 });

 

                // Specify fill color using .Net Color class

                var fillColor2 = Color.Teal;

 

                var lineColor2 = "#00ff00";

                // Create 3D polygon

                var polygon2 = SGWorld.Creator.CreatePolygon(complexGeometry2, lineColor2, fillColor2.ToArgb(), AltitudeTypeCode.ATC_TERRAIN_ABSOLUTE, string.Empty, "Polygon with 2 holes");

                polygon2.Position.Distance = 80000;

                polygon2.Position.Pitch = -45;

                SGWorld.Navigate.FlyTo(polygon2.Position, ActionCode.AC_FLYTO);

            }

            catch (Exception ex)

            {

                MessageBox.Show("Unexpected error:" + ex.Message);

            }

        }